import scrapy

class itemSpider(scrapy.Spider):

    name='ncreInfo'

    start_urls=['http://www.ncre.cn/html1/category/1507/872-1.htm']

    def parse(self, response):
        url=response.css('span#ReportIDname a::attr(href)').extract()[0]
        if url is not None:
            url=response.urljoin(url)
            yield  scrapy.Request(url, callback=self.parse_content)

    def parse_content(self,response):
        title=response.css('span#ReportIDname::text').extract()[0]
        time=response.css('span#ReportIDIssueTime::text').extract()[0]
        text=response.css('p::text').extract()
        # text=','.join(text)

        fileName='NCRE.txt'
        with open(fileName,"a+") as f:
            f.write(title)
            f.write('\n')
            f.write('发布时间：'+time+'\n')
            for t in text:
                f.write(t+'\n')
            f.close()




